package com.ostrich.demobrvah.adapter

import com.chad.library.adapter.base.BaseProviderMultiAdapter
import com.ostrich.demobrvah.R
import com.ostrich.demobrvah.entity.BaseEntity
import com.ostrich.demobrvah.entity.OneEntity
import com.ostrich.demobrvah.entity.ThreeEntity
import com.ostrich.demobrvah.entity.TwoEntity

/**
 * @Author : yaotianxue
 * @Time : On 2023/10/28 10:03
 * @Description : DemoAdapter
 */
class DemoAdapter:BaseProviderMultiAdapter<BaseEntity>() {

    init {

        addItemProvider(OneProvider(0,R.layout.item_one))
        addItemProvider(TwoProvider(1,R.layout.item_two))
        addItemProvider(ThreeProvider(2,R.layout.item_threee))
        addItemProvider(EmptyProvider(-1,R.layout.item_empty))
    }
    /**
     * 根据数据源type返回不同int类型type
     */
    override fun getItemType(data: List<BaseEntity>, position: Int): Int {
      return  when(data[position]){
              is OneEntity ->  0
              is TwoEntity->  1
              is ThreeEntity ->  2
              else -> -1
        }
    }
}